<template>
  <div class="report">
    <div id="pdfDom">
      <h2>{{ $store.state.pxswitch ?"培训":"考试" }}数据报告</h2>
      <div class="title">
        基本信息
      </div>
      <hr />
      <div class="left">
        <ul>
          <li>
            <b>{{ $store.state.pxswitch ?"培训":"考试" }}科目：</b>
            <span>{{
              reportdata.equipmentType == 1
                ? "低压排故实验"
                : "低压配电综合实验"
            }}</span>
          </li>
          <li>
            <b>学员姓名：</b> <span>{{ reportdata.studentName }}</span>
          </li>
          <li><b>{{ $store.state.pxswitch ?"培训":"考试" }}班级：</b> <span>0100014</span></li>
          <li><b>{{ $store.state.pxswitch ?"培训":"考试" }}时间：</b> <span>{{ reportdata.startTime }}</span></li>
        </ul>
      </div>
      <div class="left">
        <ul>
          <li><b>指导老师：</b> <span>{{ reportdata.usersName }}</span></li>
          <li>
            <b>学生学号：</b> <span>{{ reportdata.studentId }}</span>
          </li>
          <li>
            <b>{{ $store.state.pxswitch ?"培训":"考试" }}地点：</b> <span>{{ reportdata.title }}</span>
          </li>
          <li>
            <b>{{ $store.state.pxswitch ?"培训":"考试" }}机位：</b> <span>{{ reportdata.equipmentName }}</span>
          </li>
        </ul>
      </div>
      <div class="title">
        上机情况
      </div>
      <hr />
      <table>
        <tr>
          <th></th>
          <th>旷课</th>
          <th>迟到</th>
        </tr>
        <tr>
          <td>考勤情况</td>
          <td>0</td>
          <td>0</td>
        </tr>
      </table>
      <table>
        <tr>
          <th></th>
          <th>越界检测</th>
          <th>安全帽检测</th>
          <th>人员聚集检测</th>
          <th>工装检测</th>
        </tr>
        <tr>
          <td>违例情况</td>
          <td>{{ reportdata.outDetection }}</td>
          <td>{{ reportdata.helmetDetection }}</td>
          <td>{{ reportdata.peopleDetection }}</td>
          <td>{{ reportdata.toolingDetection }}</td>
        </tr>
      </table>

      <div class="title">
        实操情况
      </div>
      <hr />
      <table>
        <tr>
          <th></th>
          <th>接线错误</th>
          <th>接线工艺</th>
          <th>用时</th>
        </tr>
        <tr>
          <td>接线情况</td>
          <td style="padding: 0">
            <input
              v-model="mistake"
              :disabled="reprotval == 1"
              type="text"
              placeholder="请输入"
              @keyup="mistake = mistake.replace(/^(0+)|[^\d]+/g, '')"
            />
          </td>
          <td style="padding: 0">
            <input
              v-model="errState"
              :disabled="reprotval == 1"
              type="text"
              placeholder="请输入"
              @keyup="errState = errState.replace(/^(0+)|[^\d]+/g, '')"
              @blur="errBlur"
            />
          </td>
          <td>{{ reportdata.time }}分钟</td>
        </tr>
      </table>
      <div class="title">
        综合得分
      </div>
      <hr />
      <b class="zf">
        综上所示,该学员上机{{ $store.state.pxswitch ?"培训":"考试" }}得分为
        <span>
          <input
            v-model="grade"
            :disabled="reprotval == 1"
            type="text"
            placeholder="请输入"
            @keyup="grade = grade.replace(/^(0+)|[^\d]+/g, '')"
          />
        </span>
        <!-- /^(0)$|^100$|^[1-9][0-9]?$/ -->
        分
      </b>
      <br />
    </div>

    <el-button
      v-show="reprotval == 0"
      type="primary"
      @click="save"
    >
      保存
    </el-button>
    <el-button
      v-show="reprotval == 1"
      type="primary"
      @click="exportPdf()"
    >
      导出为pdf
    </el-button>
    <el-button @click="$parent.$parent.reportVisible = false">
      取消
    </el-button>
  </div>
</template>

<script>
export default {
  props: {
    reportdata: {
      type: Object,
      require: true,
      default: () => {},
    },
    reprotval: {
      type: Number,
      require: true,
      default: 1,
    },
  },
  data() {
    return {
      dialogVisible: true,
      htmlTitle: "培训报告",
      grade: "",
      mistake: "",
      errState: "", // 接线工艺
    };
  },
  watch: {
    reportdata(newVal) {
      this.htmlTitle = newVal.studentName + "的培训报告";
    },
    grade(newVal) {
      if (newVal > 100) {
        let aa = this.grade.split("");
        aa.pop();
        this.grade = aa.join("");
        this.$message.warning("请输入0-100的正整数!");
      }
    },
    errState(newVal) {
      console.log(newVal);
      //  newVal = newVal +"%"
      // Number(newVal) ? newVal = newVal +"%":console.log(666);
      // if (Number(newVal)) {
      //   this.errState = newVal + "%"
      // }
      if (newVal > 100) {
        let aa = newVal.split("");
        aa.pop();
        this.errState = aa.join("");
        this.$message.warning("请输入100以内正整数!");
      }
    },
    mistake(newVal) {
      if (newVal > 100) {
        let aa = newVal.split("");
        aa.pop();
        this.mistake = aa.join("");
        this.$message.warning("请输入100以内正整数!");
      }
    },
  },
  methods: {
    exportPdf() {
      this.getPdf("#pdfDom", this.htmlTitle);
    },
    save() {
      this.$parent.$parent.reportVisible = false;
      // this.grade = '';
      // this.mistake = '';
      // this.errState = '';
    },
    errBlur() {
      this.errState = this.errState + "%";
    },
  },
};
</script>

<style lang="scss" scoped>
.report {
  min-width: 1000px;
  background: #fff;
  position: absolute;
  padding-bottom: 15px;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  &::after {
    content: "";
    display: block;
    clear: both;
  }
  #pdfDom {
    min-width: 800px;
    padding: 20px 30px;
  }
  h2 {
    text-align: center;
    font-size: 35px;
    line-height: 2em;
  }
  .title {
    font-weight: bold;
    border-bottom: 3px solid #00bfbf;
    font-size: 25px;
    line-height: 2em;
    &::before {
      content: " ";
      display: block;
      clear: both;
    }
  }
  hr {
    margin: 2px 0 20px;
    background-color: #00bfbf;
    height: 1px;
    border: none;
  }
  input {
    border: none;
    width: 90px;
    font-size: 18px;
    background: none;
    color: #606266;
    text-align: center;
  }
  .left {
    float: left;
    font-size: 18px;
    padding-left: 50px;
    width: calc(50% - 100px);
    margin-bottom: 30px;
    li {
      width: 100%;
      line-height: 2em;
    }

    span {
      display: inline-block;
      border-bottom: 1px solid #666;
      padding: 0 10px;
      width: 60%;
      text-align: center;
    }
  }
  b {
    display: inline-block;
    line-height: 2.5em;
  }
  table {
    border: solid 1px #cccccc;
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 18px;
    margin-left: 50px;
    margin-bottom: 15px;
    td,
    th {
      padding: 8px 35px;
      text-align: center;
      border: 1px solid #ccc;
    }
    &:last-child {
      margin-bottom: 30px;
    }
  }
  .zf {
    margin-left: 50px;
    font-size: 18px;
    span {
      border-bottom: 2px solid #666;
      padding: 0 5px;
    }
  }
  .el-button {
    float: right;
    margin: 15px 30px;
    font-size: 18px;
    &:last-of-type {
      margin-right: 0;
    }
  }
}
</style>
